package com.qining618.common.interceptor;

import com.qining618.common.contants.SysConstants;
import com.qining618.common.utils.StringUtils;
import org.slf4j.MDC;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author flt
 * @date 2019-08-23
 */
public class TraceIdInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String traceId = StringUtils.get32UUID();
        MDC.put(SysConstants.TRACE_ID, traceId);
        return true;
    }

}
